package logic

import (
	"context"
	"user_srv/models"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type LiePinUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLiePinUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LiePinUpdateLogic {
	return &LiePinUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LiePinUpdateLogic) LiePinUpdate(in *user.LiePinUpdateRequest) (*user.LiePinUpdateResponse, error) {
	var lie models.LiePin
	lie.ID = uint(in.LiePinId)
	lie.Money = float64(in.Money)
	lie.Qualification = in.Qualification
	err := lie.UpdateLiePin()
	if err != nil {
		logx.Error("修改失败", err)
		return nil, err
	}

	return &user.LiePinUpdateResponse{
		LiePinId: int64(lie.ID),
	}, nil
}
